//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __CCONSOLEIO_H__
#define __CCONSOLEIO_H__

#include <stdlib.h>

#define _MALLOCA(n) (n <= HEAP_ALLOC_THRESHOLD ? _alloca(n) : malloc(n))
#define _FREEA(p, n) if (n > HEAP_ALLOC_THRESHOLD) free(p)

class CConsoleIo
{
public:
    CARAPI Init();

    CARAPI Uninit();

    CARAPI SetIo(UInt32 fd, WString ws);

    IAbsoluteIO* GetIo(UInt32 fd);

    Int32 Read();

    CARAPI ReadLine(
        /* [out] */ AStringBuf *pasBuf);

    CARAPI Write(AString as);

    Boolean IsConsole(UInt32 fd);

private://method
    Boolean IsRedirect(UInt32 fd);

private://data
    IAbsoluteIO *m_pIoFile[3];
    Int32 m_Offset[3];
    Boolean m_IsConsole[3];
    IDiskManager *m_pDiskMgr;
};

#endif // __CCONSOLEIO_H__
